﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using WpfRcp.Startup;
using WpfRcp.Core.Startup;
using WpfRcp.Core.Services;
using Microsoft.Practices.Composite.Modularity;
using System.Windows.Media.Imaging;
using RCPApplication.UI.Views;
using RCPApplication.UI.Views.Controls;
using RCPApplication.UI.Views.Presenters;
using Microsoft.Practices.Composite.Regions;
using WpfRcp.Core.Globals;
using WpfRcp.Views.Windows;
using WpfRcp.Core.Views;
using WpfRcp.Logging.EnterpriseLibrary;
using WpfRcp.Logging.EnterpriseLibrary.Controls;
using WpfRcp.Logging.Log4Net;
using WpfRcp.Logging.Log4Net.Controls;
using WpfRcp.Core.Services.Commands;
using WpfRcp.Services.Commands;
using Microsoft.Practices.Composite.Presentation.Regions;
using WpfRcp.Helpers.CompositePresentation;
using Microsoft.Windows.Controls.Ribbon;
using RibbonControls.Controls;
using RibbonControls.Helpers;
using RibbonControls.Commands;

namespace RCPApplication.UI.Startup
{
    public class WpfRcpApplicationBootstrapper: BootstrapperBase
    {
        public WpfRcpApplicationBootstrapper(IApplication application)
            : base(application)
        {
        }

        protected override void RegisterViews()
        {
            base.RegisterViews();

            // Include to choose your specific current culture
            var applicationSettings = Container.Resolve<IApplicationSettings>();
            applicationSettings.CurrentCulture = new CultureInfo("en-US");

            Container.Register<IAboutView, AboutView>();
            Container.Register<AboutViewPresentationModel, AboutViewPresentationModel>();

            var registry = Container.Resolve<IRegionViewRegistry>();
            registry.RegisterViewWithRegion(RegionNames.AboutRegion, typeof(IAboutView));

            //Container.Register<IShell, AvalonDockControls.Views.AvalonDockShell>(LifetimePolicy.Singleton);
            //Container.Register<IMenuControl, RibbonMenuControl>(LifetimePolicy.Singleton);
            //Container.Register<IMenuItemFactory, RibbonBasedMenuItemFactory>(LifetimePolicy.Singleton);

            //logging configuration

            //EntLib
            Container.Register<ILoggerService, EntLibLoggerService>(LifetimePolicy.Singleton);
            Container.Register<WpfRcp.Views.ILoggerView, EntLibLoggerView>(LifetimePolicy.Singleton);

            //log4Net
            //log4net.Config.XmlConfigurator.Configure();
            //log4net.Config.BasicConfigurator.Configure(Container.Resolve<LogManagerAppender>());
            //Container.Register<ILoggerService, Log4NetLoggerService>(LifetimePolicy.Singleton);
            //Container.Register<WpfRcp.Views.ILoggerView, Log4NetLoggerView>(LifetimePolicy.Singleton);
        }

        protected override void SetRcpSettings(IRcpSettings settings)
        {
            settings.AppName = Properties.Resources.AppName;
            settings.AppNameExtended = Properties.Resources.AppNameExtended;
            settings.TaskBarAppName = Properties.Resources.TaskBarAppName;
            settings.VersionSuffix = Properties.Resources.VersionSuffix;
            settings.Copyright = Properties.Resources.Copyright;
            settings.AboutBoxImage = BitmapFrame.Create(new Uri(@"pack://application:,,,/RCPApplication;Component/Resources/Images/User.ico", UriKind.Absolute));
            settings.SplashScreenImage = BitmapFrame.Create(new Uri(@"pack://application:,,,/RCPApplication;Component/Resources/Images/User.ico", UriKind.Absolute));
            settings.WindowIcon = BitmapFrame.Create(new Uri(@"pack://application:,,,/RCPApplication;Component/Resources/Images/User.ico", UriKind.Absolute));
        }

        protected override IModuleCatalog GetModuleCatalog()
        {
            return new WpfRcp.Helpers.CompositePresentation.DirectoryModuleCatalog { ModulePath = "." };
        }

        protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
        {
            base.ConfigureRegionAdapterMappings(regionAdapterMappings);

            regionAdapterMappings.RegisterMapping(typeof(RibbonButton),
                Container.Resolve<RibbonButtonRegionAdapter>());

        }
    }
}
